<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>带我审批</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <style type="text/css">
        .aui-list-item.wechat-top {
            background-color: #f3f3f7;
        }
        .aui-list .wechat-avatar {
            width:3rem;
        }
        .wechat-avatar .aui-row-padded {
            background-color: #dddee0;
            padding: 0.1rem;
            border-radius: 0.2rem;
            margin-left: -0.05rem;
            margin-right: -0.05rem;
        }
        .wechat-avatar .aui-row-padded [class*=aui-col-xs-] {
            padding: 0.05rem;
        }
        .wechat-avatar,
        .wechat-avatar > img {
            border-radius:0.2rem;
        }
    </style>
</head>
<body>
    <div class="aui-content aui-margin-b-15 aui-margin-t-15">
        <ul class="aui-list aui-media-list" id="work-list">
            <!-- <li class="aui-list-item aui-list-item-middle" onclick="openWin()">
                <div class="aui-media-list-item-inner">
                    <div class="aui-list-item-media wechat-avatar">
                        <img src="../image/demo5.png" />
                    </div>
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-text">
                            <div class="aui-list-item-title">报销</div>
                            <div class="aui-list-item-right">07-27 10:30</div>
                        </div>
                        <div class="aui-list-item-text aui-font-size-12">
                            admin
                        </div>
                    </div>
                </div>
            </li> -->
        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript" src="../script/aui-toast.js" ></script>
<script type="text/javascript">
var toast = new auiToast();
apiready = function(){
    // 监听 同意/驳回/转送
    api.addEventListener({
        name: 'reloadWorkflow'
    }, function(ret, err) {
        location.reload();
    });
    // 加载数据
    $api.setStorage("work_index", 0);
    load();
    //上拉翻页
    api.addEventListener({
        name : 'scrolltobottom'
    }, function(ret, err) {
        $api.setStorage("work_index", $api.getStorage("work_index") - 0 + 1);
        load();
    });

    // 下拉刷新
    api.setRefreshHeaderInfo({
        loadingImg: 'widget://image/refresh.png',
        bgColor: '#ccc',
        textColor: '#fff',
        textDown: '下拉刷新...',
        textUp: '松开刷新...'
    }, function(ret, err) {
        $('#work-list').empty();
        $api.setStorage("work_index", 0);
        load();

        api.refreshHeaderLoadDone();
    });
    // 加载内容列表
    function load () {
        // alert($api.getStorage("username"))
        api.showProgress({
           style: 'default',
           animationType: 'fade',
           title: '拼命加载中...',
           text: '不如喝茶去...',
           modal: false
        });
        api.ajax({
            url: ServeUrl + 'm=Workflow&a=getMyAgreeWork',
            method: 'post',
            dataType : 'json',
            data: {
                values: {
                    index: $api.getStorage("work_index"),
                    user : $api.getStorage("username"),
                },
            },
        }, function(ret, err) {
            // alert(JSON.stringify(err));
            if (ret) {
                var str = '';
                for (var i = 0; i < ret.length; i++) {
                    switch (ret[i].type) {
                        case '1' : var typeStr = '请假'; break;
                        case '2' : var typeStr = '外勤'; break;
                        case '3' : var typeStr = '出差'; break;
                        case '4' : var typeStr = '报销'; break;
                    }
                    str += '<li class="aui-list-item aui-list-item-middle" onclick="openWin('+ret[i].id+','+ret[i].type+",'"+ret[i].cn_name+"'"+')">';
                    str += '    <div class="aui-media-list-item-inner">';
                    str += '        <div class="aui-list-item-media wechat-avatar">';
                    if (ret[i].user_img) {
                        str += '<img src="'+ServeIp+'/include/data/headImg/'+ret[i].user_img+'" />';
                    } else {
                        str += '<img src="../image/emptyHead.jpg" />';
                    }
                    str += '        </div>';
                    str += '        <div class="aui-list-item-inner">';
                    str += '            <div class="aui-list-item-text">';
                    str += '                <div class="aui-list-item-title">'+typeStr+'</div>';
                    str += '                <div class="aui-list-item-right">'+ret[i].addtime+'</div>';
                    str += '            </div>';
                    str += '            <div class="aui-list-item-text aui-font-size-12">'+ret[i].cn_name+'</div>';
                    str += '        </div>';
                    str += '    </div>';
                    str += '</li>';
                }
                
                $('#work-list').append(str);
                api.hideProgress();
            } else {
                toast.success({
                    title:"已加载所有工作",
                    duration:2000
                });
                api.hideProgress();
            }
        });
    }
};


/*//资讯列表加载
 function load(first, index2) {
     api.showProgress({
        style: 'default',
        animationType: 'fade',
        title: '拼命加载中...',
        text: '不如喝茶去...',
        modal: false
     });
     var index = $api.getStorage("work_index");
     var username = $api.getStorage("username");
     var work_status = api.pageParam.work_status;
     var url = ServeUrl + "m=Workflow&a=workData&pageIndex=" + index + "&pageCount=15&username="+username+"&work_status="+work_status;
     ajaxRequest(url, 'get', '', function(data) {
         dealWithHtml(data, first, index);
     });

 }

 function ajaxRequest(url, method, datas, callBack) {
     api.ajax({
         url : url,
         method : method,
         cache : false,
         timeout : 30,
         dataType : 'json',
         data : {
             values : datas
         }
     }, function(ret, err) {
         if (ret.data) {
             callBack(ret, err);
         } else {
             //alert("没有更多的用户！");
             toast.success({
                 title:"已加载所有工作",
                 duration:2000
             });
             api.hideProgress();
         }
     });
 }

//字符串拼接
function dealWithHtml(data, first, index) {
    //alert(JSON.stringify(data));
    var htm = '';
    for (var i = 0; i < data.data.length; i++) {
        htm += '<li class="aui-list-item aui-list-item-middle" onclick="openWin('+data.data[i].id+')">'
        htm += '<div class="aui-media-list-item-inner">'
        htm += '<div class="aui-list-item-media wechat-avatar">'
        htm += '<img src="../image/demo1.png" />'
        htm += '</div>'
        htm += '<div class="aui-list-item-inner">'
        htm += '<div class="aui-list-item-text" >'
        htm += '<div class="aui-list-item-title">'+data.data[i].working_name+'</div>'
        htm += '</div>'
        htm += '<div class="aui-list-item-text aui-font-size-12">'+data.data[i].applicant
        htm += '<div class="aui-list-item-right">'+data.data[i].create_time+'</div>'
        htm += '</div>'
        htm += '</div>'
        htm += '</div>'
        htm += '</li>'
    }
    $("#work-list").append(htm);
    api.hideProgress();
}*/



function openWin(id, type, name) {
    // alert(name);
    api.openWin({
        name: "workflow_list_details",
        url: 'workflow_list_details_win.html',
        pageParam: {
            id: id,
            type: type,
            name: name
        }
    });
}

</script>
</html>
